/* search and nav */
jQuery(document).ready(function(){
    var delayTime = [];
    jQuery('#nav li:has(ul)').each(function(index) {
        $(this).hover(function() {
            var _self = this;
            delayTime[index] = setTimeout(function() {
                $(_self).find('ul:eq(0)').slideDown(200)
            },
            400)
        },
        function() {
            clearTimeout(delayTime[index]);
            $('ul', this).slideUp(200)
        });
    });
	
	// Search
	jQuery("input#sear_txt").val("Search...");
	textReplacement(jQuery('input#sear_txt').css("color", "#aaa"));
	function textReplacement(input){ 
	var originalvalue = input.val();
	input.focus( function(){
	if( jQuery.trim(input.val()) == originalvalue ){ input.val("").css("color", "#666"); }
	});
	 input.blur( function(){
	if( jQuery.trim(input.val()) == "" ){ input.val(originalvalue).css("color", "#aaa"); }
	});
	}
});
/* up-sider */
$(document).ready(function(){
	//auto center when window size is changed
    $(window).resize(function(){
        $bwidth=$(window).width();
        $upsibtn=$bwidth/2-25+"px";
        $upsiderbar=$bwidth/2-500+"px";
        $("#upsider").css({left:$upsibtn,opacity: "0.5"});
        $("#upsiderbar").css({left:$upsiderbar,opacity: "0.5"});
    });
    
    //auto center when page is initialized
    $bwidth=$(window).width();
    $upsibtn=$bwidth/2-25+"px";
    $upsiderbar=$bwidth/2-500+"px";
    $("#upsider").css({left:$upsibtn,opacity: "0.5"});
    $("#upsiderbar").css({left:$upsiderbar,opacity: "0.5"});
	
    //mouseover
	$("#upsider").mouseenter(function(){
	   $("#upsiderbar").fadeIn();
       $("#upsider").fadeOut();
	});

    //mouseout
    $("#upsiderbar").mouseleave(function(){
       $("#upsiderbar").fadeOut("slow");
       $("#upsider").fadeIn();
    });
	
	//onScroll
	$(window).scroll(function(){
		if($.browser.safari)
		{
		   $top=$("body")[0].scrollTop;
		}
		else
		{
			$top=$("html")[0].scrollTop;
		}
		if($top>100)
		{
			$("#upsider").fadeOut();
		}
		else
		{
			$("#upsider").fadeIn();
		}
	});
});
    function breath()
    {
        $('#upsider-inside').transition({opacity:0,scale:1.0},'2000').transition({opacity:1,scale:1.2},'2000')
        setTimeout("breath()",4000)
    }
$(document).ready(function(){
    breath()
})
/* tab switch */
$(document).ready(function(){
    var GroupLi = $(".tabhead li");
    var GroupHead = $(".tabhead li");
        $(GroupLi[0]).click(function(){
            location.href = "http://news.ziqiang.net/";
        });
        $(GroupLi[1]).click(function(){
            location.href = "http://news.ziqiang.net/category_125.html";
        });
        $(GroupLi[2]).click(function(){
            location.href = "http://news.ziqiang.net/category_144.html";
        });
        $(GroupLi[3]).click(function(){
            location.href = "http://bbs.ziqiang.net/";
        });
    GroupLi.each(function(g){
        $(GroupLi[g]).hover(function(){
            switch (g){
                case 0:
                    $(".tab1").fadeIn();$(".tab2").hide();$(".tab3").hide();$(".tab4").hide();
                    $(".tabhead li").removeClass("select");
                    $(GroupHead[0]).addClass("select");
                    break;
                case 1:
                    $(".tab2").fadeIn();$(".tab1").hide();$(".tab3").hide();$(".tab4").hide();
                    $(".tabhead li").removeClass("select");
                    $(GroupHead[1]).addClass("select");
                    break;
                case 2:
                    $(".tab3").fadeIn();$(".tab1").hide();$(".tab2").hide();$(".tab4").hide();
                    $(".tabhead li").removeClass("select");
                    $(GroupHead[2]).addClass("select");
                    break;
                case 3:
                    $(".tab4").fadeIn();$(".tab1").hide();$(".tab2").hide();$(".tab3").hide();
                    $(".tabhead li").removeClass("select");
                    $(GroupHead[3]).addClass("select");
                    break;
                default:
                    $(".tab1").fadeIn();$(".tab2").hide();$(".tab3").hide();$(".tab4").hide();
                    $(".tabhead li").removeClass("select");
                    $(GroupHead[0]).addClass("select");
                    break;
            };
        },function(){
            
        });
    });
});
